package com.health;

import com.health.adapter.MainMenuGridAdapter_AdminJTYS;
import com.health.activity.settings.SystemSettingActivity;
import com.health.tools.FTPTool;
import com.novabluetooth.views.BluetoothDeviceBindActivity2;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageView;

/**
 * 主界面【管理】
 * 
 * @author nova
 * 
 */
public class MainActivity_Menu_Admin extends NovaActivity implements android.view.View.OnClickListener{

	private GridView gd_menu;
	private MainMenuGridAdapter_AdminJTYS menuAdapter;
	private String textname;
	protected ProgressDialog progressDialog;
	private ImageView img_back;
	String admin="";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 无标题栏：
		// requestWindowFeature(Window.FEATURE_NO_TITLE);

		// 全屏：
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_main);
		findViews();
		setListeners();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void findViews() {
		
		if(getIntent().hasExtra("admin")){
			admin=getIntent().getStringExtra("admin");
		} 
		gd_menu = (GridView) findViewById(R.id.gd_menu);
		menuAdapter = new MainMenuGridAdapter_AdminJTYS(getApplicationContext(),admin);
		gd_menu.setAdapter(menuAdapter);
		img_back=(ImageView) findViewById(R.id.img_back);
		img_back.setOnClickListener(this);
		
		
	}

	@Override
	public void setListeners() {
		// 菜单选项
		gd_menu.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// 0"系统设置", 1"蓝牙设备绑定",2"数据上传", 3"综合统计"
				Intent intent = null;
				if (position == 0) {
					// 0 "系统设置",
					intent = new Intent(getApplicationContext(), SystemSettingActivity.class);
				} else if (position == 1) {
					// 1 "蓝牙设备绑定",
					intent = new Intent(getApplicationContext(), BluetoothDeviceBindActivity2.class);
				} else if (position == 2) {
					// 2 "数据上传",
					FTPTool.ftpUpdateDB(MainActivity_Menu_Admin.this);
					return;
				} else if (position == 3) {
					// 3 综合统计
					intent = new Intent(getApplicationContext(), TongjiActivity.class);
				} 
				
				if(intent!=null){
					startActivity(intent);
				}
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_back:
			finish();
			break;

		default:
			break;
		}
		
	}
	
}
